<template>
	<view class="near">
		<!-- dingwei -->
		<view class="dingwei">
			<view class="localtion" @click="getLocaltion">
				<view class="icon">
					<text class="iconfont icon-location"></text>
				</view>
				<view class="address">
					{{ realcity }}
				</view>
				<view class="mark">
					>
				</view>
			</view>
			<view class="msg">
				<text class="iconfont icon-xiaoxi1"></text>
			</view>
		</view>
		<!-- search -->
		<view class="search">
			<van-search :placeholder="Placeholder" :value="searchData" input-align="center" @change="onSearchChange"/>
		</view>
		<!-- ban -->
		<ban-ner></ban-ner>
		<!-- 附近商家 -->
		<view class="shoplist">
			<view class="title">
				附近商家{{ shopnum }}个
			</view>
			<!-- list -->
			<view class="listbox">
				<view class="item" v-for="(item, index) in shopList" :key="index">
					<view class="header">
						<view class="authmark" >
							{{ item.approve == 1 ? "认证" : "未认证" }}
						</view>
						<view class="shopname">
							{{ item.companyname }}
						</view>
					</view>
					<view class="content">
						<view class="avatar">
							<image :src="item.logo" mode=""></image>
						</view>
						<view class="desc">
							{{ item.intro }}
						</view>
						<view class="rate">
							<view class="star">
								<van-rate :value="rate" @change="onChange" :size="RateSize" />
							</view>
							<view class="done">
								已完成{{ item.count ? item.count : "0" }}次服务
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 暂无 -->
			<!-- <view class="none" v-if="shopList.length == 0">
				附近暂无商家
			</view> -->
		</view>
	</view>
</template>

<script>
	import BanNer from "@/components/public/index/BanNer.vue"
	export default {
		data() {
			return {
				rate: 5,
				RateSize: 10,
				realcity: "",
				Placeholder: "搜索商家",
				searchData: "",
				shopList: [
				],
				shopnum: "0",
			}
		},
		onShow() {
			this.getLocaltion()
			
		},
		components: {
			BanNer
		},
		computed:{
			city() {
				return this.$store.state.cityInfo.city
			}
		},
		methods: {
			// 获取商家
			async getShopList( city ) {
				let self = this
				console.log(this.city)
				let res = await this.$Request("POST", "/Index/worknum", { city: this.realcity })
				console.log(res)
				this.shopnum = res.data.data
			},
			// 获取商家详情
			getShopInfo( id ) {
				uni.navigateTo({
					url: `/pages/master/master?shopid=${id}`
				})
			},
			// 评分
			onChange() {
				
			},
			// 搜索变化
			onSearchChange(  e ) {
				// console.log(e.detail);
				this.searchData = e.detail
			},
			// 获取位置
			getLocaltion() {
				//console.log(1);
				let self = this
				uni.getLocation({
				    // type: 'wgs84',
					type:"gcj02",
					geocode: true,
				    success: function (res) {
				       // console.log(res);
						self.width = res.latitude
						self.height = res.longitude
						// self.getCity()
						uni.request({
							url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${self.width},${self.height}&key=${self.$apikey}`,
							data: {},
							success:( city ) => {
								 // console.log(city);
								self.realcity = city.data.result.ad_info.city
								self.getShopList( self.realcity )
								
							}
						})
				    }
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.near {
		width: 100%;
		box-sizing: border-box;
		.none {
			width: 100%;
			font-size: 40rpx;
			height: 200rpx;
			line-height: 200rpx;
			text-align: center;
			color: #aaa;
		}
		.dingwei {
			width: 100%;
			background-color: rgb(51,205,199);
			box-sizing: border-box;
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			color: #fff;
			.localtion {
				display: flex;
				align-items: center;
				
				font-weight: bold;
				.address {
					margin-left: 10rpx;
					max-width: 550rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 35rpx;
				}
				.mark {
					margin-left: 10rpx;
				}
			}
		}
		.shoplist {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx;
			.title {
				height: 100rpx;
				line-height: 100rpx;
				width: 100%;
				font-weight: bold;
			}
			.listbox {
				width: 100%;
				box-sizing: border-box;
				.item {
					width: 100%;
					padding: 20rpx;
					margin: 20rpx 0;
					box-shadow: 0 0 5rpx #999;
					border-radius: 30rpx;
					box-sizing: border-box;
					.header {
						width: 100%;
						height: 60rpx;
						line-height: 60rpx;
						box-sizing: border-box;
						display: flex;
						align-items: center;
						font-size: 30rpx;
						.authmark {
							width: 150rpx;
							text-align: center;
							background-color: #33CDC7;
							color: #fff;
						}
						.shopname {
							flex: 1;
							margin-left: 10rpx;
							font-weight: bold;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							font-size: 36rpx;
						}
					}
					.content {
						width: 100%;
						margin-top: 30rpx;
						
						box-sizing: border-box;
						display: flex;
						align-items: center;
						.avatar {
							width: 100rpx;
							height: 100rpx;
							overflow: hidden;
							border: 1px solid #aaa;
							image {
								width: 100rpx;
								height: 100rpx;
							}
						}
						.desc {
							margin-left: 10rpx;
							flex: 1;
							font-size: 20rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 3;
							-webkit-box-orient: vertical;
						}
						.rate {
							width: 200rpx;
							font-size: 20rpx;
							text-align: center;
						}
					}
				}
			}
		}
	}
</style>
